package com.pro.h5case.wap.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pro.h5case.common.model.BDictionary;
import com.pro.h5case.common.model.BPlan;
import com.pro.h5case.common.service.BDictionaryService;
import com.pro.h5case.common.service.BPlanService; 

@Controller
@Scope("prototype")
@RequestMapping("/detail")
public class WapDetailController {
	@Autowired
	BPlanService bPlanService;
	@Autowired
	BDictionaryService bDictionaryService;
	
	@RequestMapping("/show.html")
	public String toDetail(Model m,Integer id){
		Map<String,Object> condition = new HashMap<String,Object>();
		condition.put("planId", id);
		condition.put("planDeleteState", "1");
		condition.put("planAudit","已审核");
		bPlanService.updateWatchCountById(id);
		List<BPlan> list = bPlanService.selectByCondition(condition, 0, 1, null);
		if (list.size()>0) {
			BDictionary bDictionary = new BDictionary();
			bDictionary.setDicDeleteState((byte) 1);
			List<BDictionary> hangyeList = bDictionaryService.selectByPojo(bDictionary);
			for (int i = 0; i < list.size(); i++) {
				String [] tags = list.get(i).getPlanTag().split(",");
				String varTag="";
				if(tags.length>0){
					for (int j = 0; j < tags.length; j++) {
						for (int k = 0; k < hangyeList.size(); k++) {
							String hangye = hangyeList.get(k).getDicCode();
							if(hangye.equals(tags[j])){
								varTag +=hangyeList.get(k).getDicName() + ",";
							}
						}
					}
				}
				list.get(i).setPlanTag(varTag);
			}
			m.addAttribute("plan", list.get(0));
		}
		return "wap/detail";
	}
}
